<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : receive.class.php   FILE_PATH : \\classes\application\receive.class.php
 * ....收货地址类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri Sep 21 15:32:56 CST 2007
 */

class ReceiveClass extends FrameWork {
	/**
	 * 新增收货地址
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function addReceive($input_param){
		$arr = array();
		$arr['member_id'] = $input_param['member_id'];
		$arr['receive_code'] = $input_param['txtRcode'];
		$wherearr['receive_name'] = $arr['receive_name'] = $input_param['txtReceiveName'];
//		$wherearr['province'] = $arr['province'] = $input_param['txtProvince'];
//		$wherearr['city'] = $arr['city'] = $input_param['txtCity'];
		$wherearr['address'] = $arr['address'] = $input_param['txtAddress'];
		$wherearr['mobilephone'] = $arr['mobilephone'] = $input_param['txtMobilephone'];
		$wherearr['phone'] = $arr['phone'] = $input_param['txtPhone'];
		$wherearr['zip'] = $arr['zip'] = $input_param['txtZip'];
		$arr['receive_area_id'] = $input_param['area_id'];
		return $GLOBALS['db']->InsertRow($arr,'receive','receive_id');
	}
	
	/**
	 * 修改收货地址
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function modiReceive($input_param){
		$arr = array();
		$arr['receive_id'] = $input_param['receive_id'];
		$arr['receive_name'] = $input_param['txtReceiveName'];
//		$arr['province'] = $input_param['txtProvince'];
//		$arr['city'] = $input_param['txtCity'];
		$arr['address'] = $input_param['txtAddress'];
		$arr['mobilephone'] = $input_param['txtMobilephone'];
		$arr['phone'] = $input_param['txtPhone'];
		$arr['zip'] = $input_param['txtZip'];
		if ($input_param['area_id'] != ''){
			$arr['receive_area_id'] = $input_param['area_id'];
		}
		return $GLOBALS['db']->UpdateRow($input_param['receive_id'],$arr,'receive','receive_id');
	}
	
	/**
	 * 得到某会员的收货地址
	 *
	 * @param int $member_id
	 * @return var[]
	 */
	function getReceive($member_id){
		if (intval($member_id) > 0){
			return $GLOBALS['db']->GetList(" and member_id='" . intval($member_id) . "'",$page,"receive");
		}else {
			return false;
		}
	}
	
	/**
	 * 搜索收货人地址信息 
	 *
	 * @param var[] $condition
	 * @param obj $page
	 * @return var[]
	 */
	function getAllReceive($condition,&$obj_page){
		$subsql = $this->getCondition($condition);
		
		$receive_array = $GLOBALS['db']->GetJoinList($obj_page,array('receive','member'),"left join",array("receive.member_id=member.member_id"),array('*','login_name'),$subsql,0,array(" receive_id desc"));
		return $receive_array;
	}
	
	/**
	 * 是否存在收货地址
	 *
	 * @param string $value
	 * @param string $field
	 * @param int $member_id
	 * @return boolen
	 */
	function isExistReceive($value,$field,$member_id){
		$check_row = $GLOBALS['db']->GetOneRow($value,'receive',$field,'receive_id,member_id');
		if ($check_row['receive_id'] > 0 && $check_row['member_id'] == $member_id){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 拼接查询语句
	 *
	 * @param var[] $arr 键为字段名，值为字段对应要查找的值
	 * @return unknown
	 */
	function setWhereStr($arr){
		if (is_array($arr)){
			foreach($arr as $k=>$v){
				if ($v != ""){
					$subsql .= " and " . $k . "='" . $v . "'";
				}
			}
		}
		return $subsql;
	}
	
	/**
	 * 获得最后一条记录的ID
	 *
	 * @return unknown
	 */
	function getReceiveLastId(){
		$receive_row = $GLOBALS['db']->GetLastRow('receive','receive_id','');
		$receive_last_id = $receive_row['receive_id'];
		return $receive_last_id;
	}
	/**
	 * 删除某个会员的收货地址
	 *
	 * @param var[] $input_id
	 * @param int $member_id
	 * @return boolen
	 */
	function delReceive($input_id,$member_id){
		if (is_array($input_id)){
			foreach ($input_id as $value){
				$this->_deleteReceive($value,$member_id);
			}
		}else{
			$this->_deleteReceive($input_id,$member_id);
		}
		return true;
	}
	
	/**
	 * 删除某个会员的收货地址
	 *
	 * @param int $input_id
	 * @param int $member_id
	 * @return boolen
	 */
	function _deleteReceive($input_id,$member_id){
		if (intval($input_id) > 0){
			if ($member_id != ''){
				$sql = "and member_id='" . $member_id . "'";
			}
			$del_rs = $GLOBALS['db']->DeleOneRow(intval($input_id),'receive','receive_id',$sql);
		}
		return $del_rs;
	}
	
	/**
	 * 得到某条收货信息
	 *
	 * @param int $member_id
	 * @param int $receive_id
	 * @return var[]
	 */
	function getOneReceive($member_id,$receive_id){
		$message_array = $GLOBALS['db']->GetList("and member_id='" . $member_id . "' and receive_id='" . $receive_id . "'",$page,'receive');
		return $message_array;
	}
	
	/**
	 * 条件组合
	 *
	 * @param var[] $arr
	 * @return string
	 */
	function getCondition($arr){
		if ($arr['name'] != ""){
			$condition_sql .= " and member.login_name like'%" . $arr["name"] . "%'";
		}
		if ($arr['truename'] != ""){
			$condition_sql .= " and member.true_name like'%" . $arr["truename"] . "%'";
		}
		if ($arr['receivename'] != ""){
			$condition_sql .= " and receive.receive_name like'%" . $arr["receivename"] . "%'";
		}
		if ($arr['receive_code'] != ""){
			$condition_sql .= " and receive.receive_code = '" . $arr['receive_code'] . "'";
		}
		if ($arr['member_id'] != ""){
			$condition_sql .= " and receive.member_id = " .$arr['member_id'];
		}
		if ($arr['area_id'] != ""){
			$condition_sql .= " and receive.receive_area_id = " .$arr['area_id'];
		}
		
		return $condition_sql;
	}
}
?>